/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: javaseapp - Reg1
 * <p>Powered by webrx On 2021-08-06 16:14:25
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Reg9 {
    public static void main(String[] args) {
        String a = "java8php123javascript6mysql88888html5";
        System.out.println(a);
        // \\d
        System.out.println(a.replaceAll("\\d+?", "-")); //? 禁用贪婪

        String str = """
                <div>java php 15</div>
                <div>hello</div><div>java 14</div><div><p>java 15</p><span>java 8</p><div>java 17</div></div>
                """;
        //取出有java字符串的div标签
        Pattern p = Pattern.compile("<div>java</div>");
        Matcher m = p.matcher(str);
        while (m.find()) {
            System.out.println(m.group());
        }

        //要求 java 15 修改为java 8 其它的15 不允许修改 () 正则表达式分组
        Pattern pp = Pattern.compile("(java) (\\d+)");//$1 java  $2 15  $1 8    java 15 修改   java 8
        System.out.println(str);
        System.out.println(str.replaceAll(pp.pattern(), "$1 8"));

    }
}
